home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 007a / cug315.zip / HPGL.C < prev    next >
C/C++ Source or Header  |  1990-05-16  |  4KB  |  187 lines

  1.  
  2. /* hpgl.c is a set of functions for basic control of an HP plotter. */
  3. /* It will produce a stream of HPGL output to the designated output */
  4. /* file or device.  hpgl.c uses default coordinates for the plotter */
  5. /* (250<=x<=10250, 279<=y<=7479), with arguments in integer format */
  6. /* only. Written 3/89 by T. Clune for R. Webb.  Copyright (c) 1989, */
  7. /* Eye Research Institute, Boston, MA 02114.  All Rights Reserved. */
  8.  
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13.  
  14. #include "hpgl.h"
  15.  
  16. static void hpgl_setline();
  17.  
  18.  
  19.  
  20.  
  21. /* hpgl_endline() lifts the pen from the paper */
  22.  
  23. void hpgl_endline(f)
  24. FILE *f;
  25. {
  26.     char string[80];
  27.  
  28.     strcpy(string, "PU;PU;");
  29.     fprintf(f, "%s", string);
  30.  
  31. }
  32.  
  33.  
  34.  
  35.  
  36. /* hpgl_init() initializes the plotter for operation.  Should be called once */
  37. /* before plotter is used. */
  38.  
  39. void hpgl_init(f)
  40. FILE *f;
  41. {
  42.     char string[80];
  43.  
  44.     /* initialize plotter */
  45.     strcpy(string, INIT_STRING);
  46.     fprintf(f,"%s",string);
  47.  
  48.  
  49. }
  50.  
  51.  
  52.  
  53.  
  54. /* hpgl_label() prints the string INSTRING at the current coords */
  55.  
  56. void hpgl_label(f,instring)
  57. FILE *f;
  58. char instring[];
  59. {
  60.     char string[80];
  61.  
  62.     strcpy(string, "LB");
  63.     strcat(string,instring);
  64.     instring[0]=STRING_TERM_CHAR;
  65.     instring[1]=';';
  66.     instring[2]='\0';
  67.     strcat(string,instring);
  68.     fprintf(f,"%s",string);
  69.  
  70. }
  71.  
  72.  
  73.  
  74.  
  75. /* hpgl_line() draws a line from the current position to x,y.  If you */
  76. /* have not begun the line with hpgl_startline(), the pen will probably */
  77. /* not be on the paper, so always begin a line with that command.  */
  78. /* hpgl_line() issues neither a "pen up" nor a "pen down" command. */
  79.  
  80. void hpgl_line(f,x,y)
  81. FILE *f;
  82. int x,y;
  83. {
  84.     char string[80];
  85.  
  86.     string[0]='\0';
  87.     hpgl_setline(string,x,y);
  88.     fprintf(f,"%s",string);
  89.  
  90. }
  91.  
  92.  
  93.  
  94.  
  95.  
  96. /* hpgl_moveto() lifts the pen from the paper and positions it at x,y */
  97.  
  98. void hpgl_moveto(f,x,y)
  99. FILE *f;
  100. int x,y;
  101. {
  102.     char string[80];
  103.  
  104.     strcpy(string, "PU;PU;");
  105.     hpgl_setline(string,x,y);
  106.     fprintf(f,"%s",string);
  107.  
  108. }
  109.  
  110.  
  111.  
  112.  
  113. /* hpgl_selectpen() lets you choose the pen that will be used */
  114.  
  115. void hpgl_selectpen(f,n)
  116. FILE *f;
  117. int n;
  118. {
  119.     char string[80];
  120.     char str2[80];
  121.  
  122.     strcpy(string, "SP");
  123.     itoa(n,str2,10);
  124.     strcat(string, str2);
  125.     strcat(string, ";");
  126.     fprintf(f,"%s",string);
  127.  
  128. }
  129.  
  130.  
  131.  
  132.  
  133. /* hpgl_startline() lifts the pen, moves to x,y, and lowers the pen */
  134.  
  135. void hpgl_startline(f,x,y)
  136. FILE *f;
  137. int x,y;
  138. {
  139.     char string[80];
  140.  
  141.     strcpy(string, "PU;PU;");
  142.     hpgl_setline(string,x,y);
  143.     strcat(string,"PD;");
  144.     fprintf(f,"%s",string);
  145.  
  146. }
  147.  
  148.  
  149.  
  150. /* hpgl_write() inserts STRING in the hpgl data stream.  It is used to */
  151. /* include hpgl commands that are not explicitly implemented in this */
  152. /* library.  NOTE WELL: the inserted string must be a complete and correct */
  153. /* hpgl expression, including the ';' terminator.  No syntax checking is */
  154. /* performed by this function. */
  155.  
  156. void hpgl_write(f, string)
  157. FILE *f;
  158. char string[];
  159. {
  160.     fprintf(f,"%s",string);
  161.  
  162. }
  163.  
  164.  
  165.  
  166.  
  167. /* hpgl_setline() is an internal function for converting the integer x,y */
  168. /* arguments of a pen move to a string command.  It is called by most of */
  169. /* the externally-visible line commands. */
  170.  
  171. static void hpgl_setline(string,x,y)
  172. char string[];
  173. int x,y;
  174. {
  175.     char str2[80];
  176.  
  177.     strcat(string, "PA");
  178.     itoa(x,str2,10);
  179.     strcat(string, str2);
  180.     strcat(string,",");
  181.     itoa(y,str2,10);
  182.     strcat(string, str2);
  183.     strcat(string,";");
  184.  
  185. }
  186.  
  187.